<template lang="html">
  <section class="components-index_list-event_item" @click="$router.push({ path: `/course/${eventDetail.subjectId}` })">
    <div class="courseCon">
      <div class="leftDiv">
        <div class="portrait">
          <progressive-img :src="eventDetail.coachAvatar" alt=""/>
        </div>
        <div class="actCont">
          <div class="actTitle">
            <h1>{{eventDetail.subjectName}}</h1>
            <p>{{isShowDate ? `${this.startDate} ${eventDetail.timeLimit}`:`${eventDetail.timeLimit}`}}</p>
            <p>{{eventDetail.area}}·{{eventDetail.storeName}}</p>
          </div>
          <div class="actDetail">
            <p class="act">{{eventDetail.subjectDescription.length > 27 ? eventDetail.subjectDescription.slice(0,27) + '...' : eventDetail.subjectDescription}}</p>
            <!-- <p class="act">{{item.actArt.length > 30 ? item.actArt.slice(0,30) + '...' : item.actArt}}</p> -->
          </div>
        </div>
      </div>
      <div class="joinInfo" v-if="!this.isEnd && !this.isPreview">
          <div class="remain" v-if="eventDetail.number <= 10">
            <span>剩余{{eventDetail.number}}</span>
            <div class="mytri"></div>
          </div>
          <p>{{action}}</p>
          <p v-if="tag" class="tag">{{tag}}</p>
      </div>
      <div class="unpublished" v-else>
        <template v-if="this.isEnd">
          <p>已结束</p>
        </template>
        <template v-if="!this.isEnd && this.isPreview">
          <p>敬请</p>
          <p>期待</p>
        </template>
      </div>
    </div>
  </section>
</template>

<script>
export default {
  props: {
    eventDetail:{
      type: Object,
      required: true
    },
    isShowDate: {
      type: Boolean,
      default: true
    }
  },
  data(){
    return {
      isShowPrice: false,
      nowTime: null,
    }
  },
  computed: {
    startDate(){
      let ary = this.eventDetail.startDate.split('-')
      return `${ary[1]}月${ary[2]}日`
    },
    action(){
      if(this.isEnd){
        return '已结束'
      } else if(this.isPreview){
        return '即将降临'
      } if(this.isQueue){
        return '取消排队'
      } else if(this.isBuy){
        return '查看预约'
      } else if(this.courseDetail && this.courseDetail.number <= 0){
        return '排队'
      } else if(this.isFree){
        return '免费体验'
      } else {
        this.isShowPrice = true
        return '报名'
      }
    },
    tag(){
      if(this.isShowPrice){
        return `￥${this.eventDetail.currentPrice}`
      } else {
        return ''
      }
    },
    isEnd(){
      return this.eventDetail && this.nowTime > this.eventDetail.endTime*1000
    },
    isPreview(){
      return this.eventDetail && this.eventDetail.status == 3
    },
    isQueue(){
      return this.eventDetail && parseInt(this.eventDetail.isQueue) === 1
    },
    isBuy(){
      return this.eventDetail && parseInt(this.eventDetail.isBuy) === 1
    },
    isFree(){
      return this.eventDetail && parseFloat(this.eventDetail.currentPrice, 10) == 0
    },
  },
  created(){
    this.nowTime = Date.now()
  },
}
</script>

<style lang="scss" scoped>
@import "../../css/config";
$rightW:133px;
$rightH:278px;
.components-index_list-event_item{
  width: 100%;
  margin-bottom: 27px;
  .courseCon{
    position: relative;
    width: 100%;
    background:#101010 ;
    height: 278px;
    padding-right:$rightW ;
    color: #fff;
    border-radius: 15px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    box-sizing: border-box;
    .leftDiv{
      $portrait-width: 215px;
      width: 100%;
      display: flex;
      flex-direction: row;
      padding: 28px 10px 31px 31px+$portrait-width;
      box-sizing: border-box;
      .portrait{
        position: absolute;
        top: 28px;
        left: 31px;
        width: $portrait-width;
        height: $portrait-width;
        line-height: $portrait-width;
        img{
          display: inline-block;
          vertical-align: middle;
          width: 100%;
        }
      }
      .actCont{
        width: 100%;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        // flex: 1;
        padding-left: 22px;
        box-sizing: border-box;
        .actTitle{
          h1{
            width: 100%;
            display: block;
            font-size: 36px;
            line-height: 40px;
            color: #ff490d;
            @include text-overflow;
          }
          p{
            width: 100%;
            display: block;
            line-height: 40px;
            font-size: 21px;
            @include text-overflow;
          }
        }
        .actDetail{
          p{
            width: 100%;
            line-height: 36px;
            font-size: 21px;
            white-space: normal;
            /*overflow: hidden;*/
            /*text-overflow:ellipsis ;*/
            /*white-space: nowrap;*/
          }
        }
      }
    }
    /*右边div*/
    .joinInfo{
      position: relative;
      width: $rightW;
      height: $rightH;
      position: absolute;
      right: 0;
      background: $common-red;
      display: flex;
      flex-direction: column;
      align-items: center;
      border-radius: 0 15px 15px 0;

      .remain{
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        background: #fff;
        color: $common-red;
        height: 56px;
        width: 66px;
        padding-top: 10px;
        // position: relative;
        text-align: center;
        font-size: 20.83px;
        overflow: hidden;
      }
    }
    .joinInfo>p:nth-of-type(1){
      font-size: 29.99px;
      margin-top: 56px + 50px;
    }
    .joinInfo>p:nth-of-type(2){
      font-size: 24px;
      margin-top: 22px;
      word-break: break-all;
      word-wrap: break-word;
    }

    /*敬请期待*/
    .unpublished{
      background:$common-bg  ;
      width: $rightW;
      height: $rightH;
      position: absolute;
      right: 0;
      border-radius: 0 15px 15px 0;
      font-size: 29.99px;
      text-align: center;
      display: flex;
      flex-direction: column;
      justify-content: center;
      p{
        line-height: 50px;
      }
    }
  }

    /*空白三角*/
  .mytri{
    position: absolute;
    bottom: -2px;
    left: -2px;
    width: 0;
    height: 0;
    border-left: 35px solid transparent;
    border-right: 35px solid transparent;
    border-bottom: 20px solid $common-red;
  }
}
</style>
